//
//  WPMsgTableViewCell.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/7.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPMsgTableViewCell.h"

@interface WPMsgTableViewCell ()
@property (nonatomic, strong) UIView * backView;/**< 白色背景 */
@property (nonatomic, strong) UITextField * titleTextField;/**< 标题 */
@property (nonatomic, strong) UILabel * timeLabel;/**< 时间 */
@property (nonatomic, strong) UILabel * msgTitle;/**< 消息标题 */
@property (nonatomic, strong) UIImageView * activeImageView;/**< 活动海报 */
@property (nonatomic, strong) UILabel * msgDetailLabel;/**< 消息详情 */
@property (nonatomic, strong) UILabel * msgTopLabel;/**< 提醒 */
@property (nonatomic, strong) UITextField * showTextField;/**< 查看 */
- (void)initializeAppearance;/**< 一般界面初始化 */

@end
@implementation WPMsgTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initializeAppearance];
    }
    return self;
}

#pragma mark - init
- (void)initializeAppearance {
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.backView];
    [_backView addSubview:self.titleTextField];
    [_backView addSubview:self.timeLabel];
    UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_titleTextField.frame), 300*DHFlexibleHorizontalMutiplier(), 1)];
    line.backgroundColor = BGCOLOR;
    [_backView addSubview:line];
    [_backView addSubview:self.activeImageView];
    [_backView addSubview:self.msgTitle];
    [_backView addSubview:self.msgDetailLabel];
//    [_backView addSubview:self.msgTopLabel];
//    [_backView addSubview:self.showTextField];
}
#pragma mark - private methods
- (void)configTimeLabelText {
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:[_model.createDate doubleValue]/1000];
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    _timeLabel.text = [formatter stringFromDate:date];
}
#pragma mark - setter
- (void)setModel:(WPMsgModel *)model {
    _model = model;
    _msgTitle.text = model.title;
    [self configTimeLabelText];
    _msgDetailLabel.text = model.content;
}

#pragma mark - getter
- (UIView *)backView {
    if (!_backView) {
        _backView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 10*DHFlexibleHorizontalMutiplier(), 300*DHFlexibleHorizontalMutiplier(), 120*DHFlexibleHorizontalMutiplier())];
            view.layer.cornerRadius = 5*DHFlexibleHorizontalMutiplier();
            view.layer.masksToBounds = YES;
            view.backgroundColor = [UIColor whiteColor];
            view;
        });
    }
    return _backView;
}
- (UITextField *)titleTextField {
    if (!_titleTextField) {
        _titleTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 260*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UIView * leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 35*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(5*DHFlexibleHorizontalMutiplier(), 5*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            image.layer.cornerRadius = 5*DHFlexibleHorizontalMutiplier();
            image.layer.masksToBounds = YES;
            image.image = IMAGE_NAME(@"iconfont_qitaguanfangyanzheng");
            [leftView addSubview:image];
            text.leftView = leftView;
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.userInteractionEnabled = NO;
            text.textColor = COLOR_RGB(170, 170, 170, 1);
            text.text = @"系统消息提醒";
            text;
        });
    }
    return _titleTextField;
}
- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(150*DHFlexibleHorizontalMutiplier(), 0, 145*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:10*DHFlexibleHorizontalMutiplier()];
            lab.textAlignment = NSTextAlignmentRight;
            lab.textColor = COLOR_RGB(170, 170, 170, 1);

            lab;
        });
    }
    return _timeLabel;
}
- (UIImageView *)activeImageView {
    if (!_activeImageView) {
        _activeImageView = ({
            UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 38*DHFlexibleHorizontalMutiplier(), 60*DHFlexibleHorizontalMutiplier(), 60*DHFlexibleHorizontalMutiplier())];
            view.image = IMAGE_NAME(@"XIAOXRAIN");
            view;
        });
    }
    return _activeImageView;
}
- (UILabel *)msgTitle {
    if (!_msgTitle) {
        _msgTitle = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(85*DHFlexibleHorizontalMutiplier(), CGRectGetMinY(self.activeImageView.frame), 200, 20*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            lab.textColor = COLOR_RGB(82, 82, 82, 1);
            lab;
        });
    }
    return _msgTitle;
}
- (UILabel *)msgDetailLabel {
    if (!_msgDetailLabel) {
        _msgDetailLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(85*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.msgTitle.frame), 205*DHFlexibleHorizontalMutiplier(), 40*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.textColor =  COLOR_RGB(103, 103, 103, 1);
            lab.numberOfLines = 0;
            lab;
        });
    }
    return _msgDetailLabel;
}
- (UILabel *)msgTopLabel {
    if (!_msgTopLabel) {
        _msgTopLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(85*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.msgDetailLabel.frame), 205*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:10*DHFlexibleHorizontalMutiplier()];
            lab.textColor = COLOR_RGB(163, 163, 163, 1);
            lab.numberOfLines = 0;
            lab;
        });
    }
    return _msgTopLabel;
}
- (UITextField *)showTextField {
    if (!_showTextField) {
        _showTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(200*DHFlexibleHorizontalMutiplier(), 130*DHFlexibleHorizontalMutiplier(), 95*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            UIView * rightView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 15*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            UIImageView * directImage = [[UIImageView alloc]initWithFrame:CGRectMake(6*DHFlexibleHorizontalMutiplier(), 10.5*DHFlexibleHorizontalMutiplier(), 5*DHFlexibleHorizontalMutiplier(), 9*DHFlexibleHorizontalMutiplier())];
            directImage.image = IMAGE_NAME(@"iconfont-xialaanniu.png");
            [rightView addSubview:directImage];
            text.rightViewMode = UITextFieldViewModeAlways;
            text.rightView = rightView;
            text.userInteractionEnabled = NO;
            text.textColor = COLOR_RGB(105, 105, 105, 1);
            text.font = [UIFont systemFontOfSize:10*DHFlexibleHorizontalMutiplier()];
            text.textAlignment = NSTextAlignmentRight;
            text.text = @"查看详情";
            text;
            
        });
    }
    return _showTextField;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
